package com.yanqu.road.server.cmd.banquet.crossBanquet.auto;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.banquet.CrossBanquetProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = Protocol.S_BANQUET_CROSS_ACTIVITY_JOIN_AUTO_LOG, desc = "自动赴宴设置")
public class BanquetAutoJoinLogCmd extends AbstractCommand {

	private CrossBanquetProto.BanquetAutoJoinSetReq reqMsg;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		reqMsg = CrossBanquetProto.BanquetAutoJoinSetReq.parseFrom(packet.getBytes());
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ActivityInfo crbAcInfo = NormalActivityMgr.getActivityInfo(reqMsg.getAcId());
		//必须是跨服争霸，就是三个区服的才能开宴会
		if(crbAcInfo == null || crbAcInfo.getServerIdList().size() <= 2){
			ret = GameErrorCode.E_BANQUET_CROSS_RANK_ACTIVITY_OVER;
			return;
		}

		YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.C_CROSS_BANQUET_JOIN_AUTO_LOG, reqMsg);
		GamePlayerMgr.sendPacket(player.getUserId(), pbMsg);
	}

	@Override
	public void sendData(GamePlayer player) {
		if(ret != 0){
			CrossBanquetProto.BanquetAutoJoinLogResp.Builder respMsg = CrossBanquetProto.BanquetAutoJoinLogResp.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_BANQUET_CROSS_ACTIVITY_JOIN_AUTO_LOG, respMsg);
		}
	}
}
